/**
 * @fileOverview
 * @author rekey
 * Created by rekey on 24/5/14.
 */

/*
* 将普通函数包装成 Promise
* @return Promise
* */
module.exports = function (fn) {
  return function () {
    var args = [].slice.call(arguments, 0);
    return new Promise(function (resolve, reject) {
      args.push(function (err, data) {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      });
      fn.apply(null, args);
    });
  };
};